async function t(t) {
    wx.chooseImage({
        count: 1,
        sourceType: [ "album", "camera" ],
        success: async function(i) {
            var a = i.tempFilePaths;
            console.log(a)
            let imgData = await getApp().checkImg(a[0])
            if(!imgData||imgData.result.errCode!==0){
                wx.showModal({
                confirmText: '确定',
                content: '图片内容不合法，请重新选择',
                showCancel: false
                })
                return
            }
            t.setData({
                imageNotChoosed: !1,
                tempImageSrc: a[0],
                originImageSrc: a[0]
            }), e(t);
        },
        fail: function(e) {
            t.setData({
                imageNotChoosed: !0
            });
        }
    });
}

function e(t) {
    wx.getImageInfo({
        src: t.data.tempImageSrc,
        success: function(e) {
            t.oldScale = 1, t.initRatio = e.height / t.imgViewHeight, t.initRatio < e.width / (750 * t.deviceRatio) && (t.initRatio = e.width / (750 * t.deviceRatio)), 
            t.scaleWidth = e.width / t.initRatio, t.scaleHeight = e.height / t.initRatio, t.initScaleWidth = t.scaleWidth, 
            t.initScaleHeight = t.scaleHeight, t.startX = 750 * t.deviceRatio / 2 - t.scaleWidth / 2, 
            t.startY = t.imgViewHeight / 2 - t.scaleHeight / 2, t.setData({
                imgWidth: t.scaleWidth,
                imgHeight: t.scaleHeight,
                imgTop: t.startY,
                imgLeft: t.startX
            }), wx.hideLoading();
        }
    });
}

function i(t) {
    wx.getImageInfo({
        src: t.data.tempImageSrc,
        success: function(e) {
            t.initRatio = e.height / t.imgViewHeight, t.initRatio < e.width / (750 * t.deviceRatio) && (t.initRatio = e.width / (750 * t.deviceRatio)), 
            t.scaleWidth = e.width / t.initRatio, t.scaleHeight = e.height / t.initRatio, t.initScaleWidth = t.scaleWidth, 
            t.initScaleHeight = t.scaleHeight, t.startX = -t.scaleWidth / 2, t.startY = -t.scaleHeight / 2, 
            t.ctx = wx.createCanvasContext("myCanvas"), t.ctx.translate(750 * t.deviceRatio / 2, t.imgViewHeight / 2), 
            t.ctx.drawImage(t.data.tempImageSrc, t.startX, t.startY, t.scaleWidth, t.scaleHeight), 
            t.ctx.draw();
        }
    });
}

function a(t, e, i) {
    setTimeout(function() {
        wx.canvasToTempFilePath({
            x: 0,
            y: 0,
            width: t.data.tempCanvasWidth,
            height: t.data.tempCanvasHeight,
            destWidth: t.data.tempCanvasWidth,
            destHeight: t.data.tempCanvasHeight,
            fileType: "png",
            quality: 1,
            canvasId: "tempCanvas",
            success: function(e) {
                wx.hideLoading(), console.log(e.tempFilePath), t.setData({
                    tempImageSrc: e.tempFilePath
                }), i && i(t);
            }
        });
    }, e);
}

function o(t, e) {
    wx.canvasToTempFilePath({
        x: 750 * t.deviceRatio / 2 + t.startX,
        y: t.imgViewHeight / 2 + t.startY,
        width: t.scaleWidth,
        height: t.scaleHeight,
        canvasId: "myCanvas",
        success: function(i) {
            if (t.cleared) {
                t.cleared = !1, t.setData({
                    doodleImageSrc: i.tempFilePath,
                    tempCanvasWidth: t.scaleWidth,
                    tempCanvasHeight: t.scaleHeight
                });
                var o = wx.createCanvasContext("tempCanvas");
                o.drawImage(t.data.tempImageSrc, 0, 0, t.scaleWidth, t.scaleHeight), o.drawImage(t.data.doodleImageSrc, 0, 0, t.scaleWidth, t.scaleHeight), 
                o.draw(), a(t, 100, e);
            } else t.setData({
                tempImageSrc: i.tempFilePath,
                originImageSrc: i.tempFilePath
            }), e(t);
        }
    });
}

var s = function() {
    function t(t, e) {
        var i = [], a = !0, o = !1, s = void 0;
        try {
            for (var n, c = t[Symbol.iterator](); !(a = (n = c.next()).done) && (i.push(n.value), 
            !e || i.length !== e); a = !0) ;
        } catch (t) {
            o = !0, s = t;
        } finally {
            try {
                !a && c.return && c.return();
            } finally {
                if (o) throw s;
            }
        }
        return i;
    }
    return function(e, i) {
        if (Array.isArray(e)) return e;
        if (Symbol.iterator in Object(e)) return t(e, i);
        throw new TypeError("Invalid attempt to destructure non-iterable instance");
    };
}(), n = getApp();

Page({
    data: {
        tempCanvasWidth: 0,
        tempCanvasHeight: 0,
        imgViewHeight: 0,
        page: "mainPage",
        imageNotChoosed: !0,
        minScale: .5,
        maxScale: 2.5,
        doodleImageSrc: "",
        tempImageSrc: "",
        originImageSrc: "",
        imgWidth: 0,
        imgHeight: 0,
        imgTop: 0,
        imgLeft: 0,
        isCroper: !1,
        cutW: 0,
        cutH: 0,
        cutL: 0,
        cutT: 0,
        canvasHeight: 0,
        isChooseWidth: !1,
        isChooseColor: !1,
        isEraser: !1,
        allColor: [ "#000000", "#7f7f7f", "#880015", "#ed1c24", "#ff7f27", "#fff200", "#22b14c", "#00a2e8", "#ffaec9", "#a349a4", "#ffffff", "#c3c3c3" ],
        isChooseFontSize: !1,
        isChooseFontColor: !1,
        isChooseFontPattern: !1,
        allText: {},
        inputFocus: !1,
        ad: {}
    },
    onShow(){
        this.setData({
            ad: ''
        });
        this.setData({
            ad: getApp().globalData.selfAd[parseInt(getApp().globalData.selfAd.length*Math.random())]
        });
        console.log(1)
    },
    onLoad: function() {
        var t = this;
        t.device = n.globalData.myDevice, t.deviceRatio = t.device.windowWidth / 750, 
        t.imgViewHeight = t.device.windowHeight - 160 * t.deviceRatio, t.setData({
            imgViewHeight: t.imgViewHeight,
            page: "mainPage"
        });
    },
    changdePic: function() {
        this.chooseOneImage();
    },
    chooseOneImage: function() {
        t(this);
    },
    toMainPage: function() {
        e(this), this.setData({
            page: "mainPage"
        });
    },
    toCropPage: function() {
        if (!this.checkPhotoSelect()) {
            var t = this;
            e(t), t.setData({
                page: "cropPage",
                allText: {}
            });
        }
    },
    bestShow: function() {
        e(this);
    },
    uploadScaleStart: function(t) {
        var e = this, i = void 0, a = void 0, o = s(t.touches, 2), n = o[0], c = o[1];
        e.touchX = n.clientX, e.touchY = n.clientY, e.imgLeft = e.startX, e.imgTop = e.startY, 
        t.touches.length >= 2 && (e.initLeft = (750 * e.deviceRatio / 2 - e.imgLeft) / e.oldScale, 
        e.initTop = (e.imgViewHeight / 2 - e.imgTop) / e.oldScale, i = c.clientX - n.clientX, 
        a = c.clientY - n.clientY, e.oldDistance = Math.sqrt(i * i + a * a));
    },
    uploadScaleMove: function(t) {
        c(this, t);
    },
    uploadScaleEnd: function(t) {
        var e = this;
        e.oldScale = e.newScale || e.oldScale, e.startX = e.imgLeft || e.startX, e.startY = e.imgTop || e.startY;
    },
    croperStart: function(t) {
        this.croperX = t.touches[0].clientX, this.croperY = t.touches[0].clientY;
    },
    croperMove: function(t) {
        var e = this, i = t.touches[0].clientX - e.croperX, a = t.touches[0].clientY - e.croperY, o = Math.max(0, e.data.imgLeft), s = Math.max(0, e.data.imgTop), n = Math.min(750 * e.deviceRatio - e.data.cutW, e.data.imgLeft + e.data.imgWidth - e.data.cutW), c = Math.min(e.imgViewHeight - e.data.cutH, e.data.imgTop + e.data.imgHeight - e.data.cutH), h = e.data.cutL + i, l = e.data.cutT + a;
        h < o && (h = o), h > n && (h = n), l < s && (l = s), l > c && (l = c), this.setData({
            cutL: h,
            cutT: l
        }), e.croperX = t.touches[0].clientX, e.croperY = t.touches[0].clientY;
    },
    dragPointStart: function(t) {
        var e = this;
        e.dragStartX = t.touches[0].clientX, e.dragStartY = t.touches[0].clientY, e.initDragCutW = e.data.cutW, 
        e.initDragCutH = e.data.cutH;
    },
    dragPointMove: function(t) {
        var e = this, i = Math.min(750 * e.deviceRatio, e.data.imgLeft + e.data.imgWidth), a = Math.min(e.imgViewHeight, e.data.imgTop + e.data.imgHeight), o = Math.min(t.touches[0].clientX, i), s = Math.min(t.touches[0].clientY, a), n = o - e.dragStartX, c = s - e.dragStartY;
        n + e.initDragCutW >= 0 && c + e.initDragCutH >= 0 && e.setData({
            cutW: e.initDragCutW + n,
            cutH: e.initDragCutH + c
        });
    },
    openCroper: function() {
        var t = Math.max(0, this.data.imgLeft), e = Math.max(0, this.data.imgTop);
        this.setData({
            isCroper: !0,
            cutW: 150,
            cutH: 100,
            cutL: t,
            cutT: e
        });
    },
    checkPhotoSelect: function() {
        if (this.data.imageNotChoosed) return wx.showModal({
            title: "提示",
            content: "请先选择图片",
            showCancel: !1
        }), !0;
    },
    competeCrop: function() {
        var t = this;
        wx.showLoading({
            title: "截取中",
            mask: !0
        });
        var i = (t.data.cutL - t.data.imgLeft) * t.initRatio / t.oldScale, o = (t.data.cutT - t.data.imgTop) * t.initRatio / t.oldScale, s = t.data.cutW * t.initRatio / t.oldScale, n = t.data.cutH * t.initRatio / t.oldScale;
        t.setData({
            isCroper: !1,
            tempCanvasWidth: s,
            tempCanvasHeight: n
        }), s < t.scaleWidth * t.initRatio / t.oldScale / 2 && (s *= 2, n *= 2);
        var c = wx.createCanvasContext("tempCanvas");
        c.drawImage(t.data.tempImageSrc, i, o, s, n, 0, 0, s, n), c.draw(), a(t, 100, e);
    },
    cancelCrop: function() {
        this.setData({
            isCroper: !1
        });
    },
    toDoodlePage: function() {
        if (!this.checkPhotoSelect()) {
            var t = this;
            i(t), t.setData({
                page: "doodlePage",
                canvasHeight: t.device.windowHeight - 160 * t.deviceRatio,
                allText: {}
            });
        }
    },
    doodleStart: function(t) {
        var e = this;
        e.lineWidth = e.lineWidth ? e.lineWidth : 5, e.lineColor = e.lineColor ? e.lineColor : "#000000", 
        this.setData({
            isChooseWidth: !1,
            isChooseColor: !1,
            canvasHeight: e.device.windowHeight - 160 * e.deviceRatio
        }), e.doodleStartX = t.touches[0].x - 375 * e.deviceRatio, e.doodleStartY = t.touches[0].y - e.imgViewHeight / 2;
    },
    doodleMove: function(t) {
        var e = this;
        e.doodled = !0, e.data.isEraser ? (e.ctx.clearRect(t.touches[0].x - 375 * e.deviceRatio, t.touches[0].y - e.imgViewHeight / 2, 30, 30), 
        e.ctx.draw(!0), e.cleared = !0) : (e.ctx.setStrokeStyle(e.lineColor), e.ctx.setLineWidth(e.lineWidth), 
        e.ctx.setLineCap("round"), e.ctx.setLineJoin("round"), e.ctx.moveTo(e.doodleStartX, e.doodleStartY), 
        e.ctx.lineTo(t.touches[0].x - 375 * e.deviceRatio, t.touches[0].y - e.imgViewHeight / 2), 
        e.ctx.stroke(), e.ctx.draw(!0)), e.doodleStartX = t.touches[0].x - 375 * e.deviceRatio, 
        e.doodleStartY = t.touches[0].y - e.imgViewHeight / 2;
    },
    chooseLineWidth: function() {
        this.setData({
            isChooseColor: !1,
            isChooseWidth: !0,
            isEraser: !1,
            canvasHeight: this.device.windowHeight - 360 * this.deviceRatio
        });
    },
    widthSliderChange: function(t) {
        this.lineWidth = t.detail.value;
    },
    chooseLineColor: function() {
        this.setData({
            isChooseColor: !0,
            isChooseWidth: !1,
            canvasHeight: this.device.windowHeight - 360 * this.deviceRatio,
            isEraser: !1
        });
    },
    lineColorChange: function(t) {
        this.lineColor = t.target.dataset.selected;
    },
    chooseEraser: function() {
        this.setData({
            isEraser: !this.data.isEraser
        });
    },
    chooseClear: function() {
        this.ctx.clearRect(-750 * this.deviceRatio / 2, -this.imgViewHeight / 2, 750 * this.deviceRatio, this.imgViewHeight), 
        this.ctx.draw(!0), this.setData({
            isEraser: !1
        }), this.cleared = !0;
    },
    doodleToMainPage: function() {
        this.doodled ? (this.doodled = !1, wx.showLoading({
            title: "保存涂鸦",
            mask: !0
        }), o(this, e), this.setData({
            page: "mainPage"
        })) : e(this), this.setData({
            page: "mainPage"
        });
    },
    toTextPage: function() {
        if (!this.checkPhotoSelect()) {
            var t = this;
            e(t), t.setData({
                page: "textPage"
            });
        }
    },
    focusInput: function() {
        this.setData({
            inputFocus: !this.data.inputFocus
        });
    },
    inputText: function(t) {
        var e = this.data.allText;
        e.someText = t.detail.value, 0 == e.someText.length && (e.someText = "点击输入文字"), 
        this.setData({
            allText: e
        });
    },
    textMoveStart: function(t) {
        this.textX = t.touches[0].clientX, this.textY = t.touches[0].clientY;
    },
    textMove: function(t) {
        var e = this.data.allText, i = t.touches[0].clientX - this.textX, a = t.touches[0].clientY - this.textY, o = 650 * this.deviceRatio, s = this.imgViewHeight - 40 * this.deviceRatio, n = e.textL + i, c = e.textT + a;
        n < 0 && (n = 0), n > o && (n = o), c < 0 && (c = 0), c > s && (c = s), e.textL = n, 
        e.textT = c, this.setData({
            allText: e,
            isChooseFontSize: !1,
            isChooseFontColor: !1,
            isChooseFontPattern: !1
        }), this.textX = t.touches[0].clientX, this.textY = t.touches[0].clientY;
    },
    chooseaddText: function() {
        var t = {};
        t = {
            idx: t.length - 1,
            someText: "点击输入文字",
            fontColor: this.fontColor ? this.fontColor : "rgba(20,20,20,0.8)",
            fontSize: this.fontSize ? this.fontSize : 14,
            fontStyle: "normal",
            fontWeight: "normal",
            textL: 550 * this.deviceRatio / 2,
            textT: this.imgViewHeight / 2 - this.scaleHeight / 2 + 20,
            isTextActive: !0
        }, this.setData({
            allText: t,
            isChooseFontSize: !1,
            isChooseFontColor: !1,
            isChooseFontPattern: !1
        });
    },
    cancelAddText: function() {
        var t = this.data.allText;
        t.isTextActive = !1, this.setData({
            allText: t,
            inputFocus: !1,
            isChooseFontSize: !1,
            isChooseFontColor: !1,
            isChooseFontPattern: !1
        });
    },
    async competeAddText () {
        let checkdata = await getApp().checkMsg(this.data.allText.someText)
        console.log(checkdata)
        if(!checkdata||checkdata.result.errCode!==0){
            wx.showModal({
            confirmText: '确定',
            content: '输入内容含有敏感词，请重新输入',
            showCancel: false
            })
            return
        }
        var t = this, e = this.data.allText;
        if ("点击输入文字" == e.someText || "" == e.someText) this.cancelAddText(); else {
            wx.showLoading({
                title: "保存文字",
                mask: !0
            }), e.isTextActive = !1;
            var i = t.initRatio;
            t.initRatio < 1 && (i = 1);
            var o = t.scaleWidth * i, s = t.scaleHeight * i;
            this.setData({
                allText: e,
                inputFocus: !1,
                isChooseFontSize: !1,
                isChooseFontColor: !1,
                isChooseFontPattern: !1,
                tempCanvasWidth: o,
                tempCanvasHeight: s
            });
            var n = wx.createCanvasContext("tempCanvas");
            n.drawImage(t.data.tempImageSrc, 0, 0, o, s), n.setFillStyle(e.fontColor);
            var c = Math.ceil(e.fontSize * i);
            n.font = e.fontStyle + " " + e.fontWeight + " " + c + "px sans-serif", n.setTextAlign("left"), 
            n.setTextBaseline("top"), n.fillText(e.someText, (e.textL - t.startX) * i, (e.textT - t.startY + 5) * i), 
            n.draw(), a(t, 100, null);
        }
    },
    chooseFontsize: function() {
        this.setData({
            isChooseFontSize: !this.data.isChooseFontSize,
            isChooseFontColor: !1,
            isChooseFontPattern: !1
        });
    },
    fontsizeSliderChange: function(t) {
        this.fontSize = t.detail.value;
        var e = this.data.allText;
        e !== {} && e.isTextActive && (e.fontSize = this.fontSize, this.setData({
            allText: e
        }));
    },
    chooseFontColor: function() {
        this.setData({
            isChooseFontSize: !1,
            isChooseFontColor: !this.data.isChooseFontColor,
            isChooseFontPattern: !1
        });
    },
    fontColorChange: function(t) {
        this.fontColor = t.target.dataset.selected;
        var e = this.data.allText;
        e && e.isTextActive && (e.fontColor = this.fontColor, this.setData({
            allText: e
        }));
    },
    chooseFontPattern: function() {
        this.setData({
            isChooseFontSize: !1,
            isChooseFontColor: !1,
            isChooseFontPattern: !this.data.isChooseFontPattern
        });
    },
    fontStyleChange: function(t) {
        this.fontStyle = t.detail.value ? "oblique" : "normal";
        var e = this.data.allText;
        e !== {} && e.isTextActive && (e.fontStyle = this.fontStyle, this.setData({
            allText: e
        }));
    },
    fontWeightChange: function(t) {
        this.fontWeight = t.detail.value ? "bold" : "normal";
        var e = this.data.allText;
        e !== {} && e.isTextActive && (e.fontWeight = this.fontWeight, this.setData({
            allText: e
        }));
    },
    textToMainPage: function() {
        e(this), this.setData({
            allText: [],
            page: "mainPage"
        });
    },
    saveImgToPhone: function() {
        wx.navigateTo({
            url: "/pages/preview/preview?imageurl=" + this.data.tempImageSrc
        });
    },
    onReady: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {
        return {
            title: "图片编辑-图片编辑助手",
            path: "pages/modifyPhoto/modify"
        };
    }
});

var c = function(t, e) {
    var i = null;
    return function() {
        var a = +new Date(), o = this, s = arguments;
        i || (i = a);
        var n = a - i;
        e && n >= e && (t.apply(o, s), i = a);
    };
}(function(t, e) {
    var i = t.data, a = i.minScale, o = i.maxScale, n = s(e.touches, 2), c = n[0], h = n[1], l = void 0, d = void 0, r = void 0, g = void 0, u = void 0;
    e.timeStamp - t.timeOneFinger < 100 || (1 === e.touches.length && (l = c.clientX - t.touchX, 
    d = c.clientY - t.touchY, t.imgLeft = t.startX + l, t.imgTop = t.startY + d, t.setData({
        imgTop: t.imgTop,
        imgLeft: t.imgLeft
    })), e.touches.length >= 2 && (g = h.clientX - c.clientX, u = h.clientY - c.clientY, 
    r = Math.sqrt(g * g + u * u), t.newScale = t.oldScale + .005 * (r - t.oldDistance), 
    t.newScale <= a && (t.newScale = a), t.newScale >= o && (t.newScale = o), t.scaleWidth = t.newScale * t.initScaleWidth, 
    t.scaleHeight = t.newScale * t.initScaleHeight, t.imgLeft = 750 * t.deviceRatio / 2 - t.newScale * t.initLeft, 
    t.imgTop = t.imgViewHeight / 2 - t.newScale * t.initTop, t.setData({
        imgTop: t.imgTop,
        imgLeft: t.imgLeft,
        imgWidth: t.scaleWidth,
        imgHeight: t.scaleHeight
    })));
}, 100);